<?php
		require_once ('nusoap/nusoap.php');
		global $HTTP_RAW_POST_DATA;
		$server = new soap_server ();
		$_SERVER['PHP_SELF'] = '/vpt/sms/';	//TIPS for nusoap
		$server->configureWSDL ('smsGateway1', 'urn:message');
		$server->register (
			'smsGateway',
			array(
				'User_ID' => 'xsd:string',
				'Service_ID' => 'xsd:string',
				'Command_Code' => 'xsd:string',
				'Message' => 'xsd:string',
				'Request_ID' => 'xsd:string' 
			),
			array ('result' => 'xsd:int' ),
			'urn:message', 'urn:message#smsGateway'
		);
		$HTTP_RAW_POST_DATA = isset ( $HTTP_RAW_POST_DATA ) ? $HTTP_RAW_POST_DATA : '';
		//error_log("HTTP_RAW_POST_DATA: ".strtoupper($HTTP_RAW_POST_DATA), 3, "/home/www/sms/logs/error_log");
		$server->service($HTTP_RAW_POST_DATA);
	function smsGateway($User_ID,$Service_ID,$Command_Code,$Message, $Request_ID) {	
		if(@$_SERVER['REMOTE_ADDR']!="203.162.70.229" && @$_SERVER['REMOTE_ADDR']!="183.91.3.139" && @$_SERVER['REMOTE_ADDR']!="118.70.67.78"){
			header("Location: http://sms1.moba.vn/");
		}
		//$endpoint = 'http://lt.socialgame.vn/sms1/';
		//include dirname(dirname(__FILE__)).'/admin/FC.php';
		//$lg_id=writeLog($User_ID,$Service_ID,$Command_Code,$Message,$Request_ID,"");
		$endpoint='';
		if(strtoupper($Command_Code) == 'LT'){
            $msg = explode(" ",$Message);
            if(isset($msg[1]) && strtoupper($msg[1]) == 'COIN')
                $endpoint = 'http://linhtrieu.vn/vpt/sms/';
            else
                $endpoint = 'http://lt.socialgame.vn/sms1/';

		}
		if(strtoupper($Command_Code) == 'BC'){			
			$endpoint = 'http://bc.socialgame.vn/sms1/';
		}
		if(strtoupper($Command_Code) == 'MV'){			
			$endpoint = 'http://mv.socialgame.vn/sms1/';
		}
		if(strtoupper($Command_Code) == 'RS'){			
			$endpoint = 'http://game.moba.vn/sms/';
		}
		if(strtoupper($Command_Code) == 'WAP'){			
			$endpoint = 'http://v-teen.vn/sms/';
		}
		if(strtoupper($Command_Code) == 'MBG'){   
   			$endpoint = 'http://mxh.moba.vn/sms/';
  		}
		if(strtoupper($Command_Code) == 'TDHV'){   
   			$endpoint = 'http://tdhv.socialgame.vn/sms/';
  		}
  		if(strtoupper($Command_Code) == 'HV2'){   
   			$endpoint = 'http://tdhv.socialgame.vn/sms/';
  		}
  		if(strtoupper($Command_Code) == 'TQQL'){  
   			$endpoint = 'http://s0.tamquoc.moba.vn/wap/sms/';
  		}
  		if(strtoupper($Command_Code) == 'HTTL'){  
   			$endpoint = 'http://www.huyenthoaithanlinh.com/sms/';
  		}
        if(strtoupper($Command_Code) == 'LV'){
            $endpoint = 'http://linhvuong.moba.vn/sms1/';
        }
  		if(strtoupper($Command_Code) == 'TQ'){	
  			$mess = explode(" ",$Message);
			if(strtoupper($mess['1'])=='TQ2'){
				$endpoint = 'http://s2.tamquoc.moba.vn/sms1/';
			}else{		
				$endpoint = 'http://s1.tamquoc.moba.vn/sms1/';
			}
		}
  		if(strtoupper($Command_Code) == 'TRAU'){  
   			$endpoint = 'http://hungvuong.moba.vn/sms/';
  		}		
		if(strtoupper($Command_Code) == 'VPT'){  
   			$endpoint = 'http://vuaphepthuat.moba.vn/sms/';
  		}		
		if(strtoupper($Command_Code) == 'TN'){  
   			$endpoint = 'http://thanhnu.vn/sms/';
  		}		
		//error_log("HTTP_RAW_POST_DATA: ".strtoupper($HTTP_RAW_POST_DATA), 3, "/home/www/sms/sms/error.log");
		
		require_once ('nusoap/nusoap.php');

		$client = new nusoap_client($endpoint,false);
		/*$err = $client->getError();
		if ($err) {
    		echo "<h2>Constructor error</h2><pre>" . $err . "</pre>";
    	}*/

		$params =  array(
			'User_ID' => $User_ID,
			'Message' => $Message,
			'Service_ID' => $Service_ID,
			'Command_Code' => $Command_Code,
			'Request_ID' => $Request_ID
		);
		$result = $client->call('smsGateway',$params);
		//$ret=updateLog(array("lg_id"=>$lg_id,"result"=>$result,"is_error"=>0));
		/*if ($client->fault) {
		    echo "<h2>Fault</h2><pre>";
		    print_r($result);
		    echo "</pre>";
		} else {
		    // Check for errors
		    $err = $client->getError();
		    if ($err) {
		    // Display the error
		    echo "<h2>Error</h2><pre>" . $err . "</pre>";
		    } else {
		    // Display the result
		    echo "<h2>Result</h2><pre>";
		    print_r($result);
		    }
		}*/

		//return $result;
		return 0;
		
	}
